from app.db import SessionLocal
from app.models.models import Student
from sqlalchemy import text

def check_database():
    db = SessionLocal()
    try:
        print("\n=== 检查数据库表 ===")
        result = db.execute(text("SELECT name FROM sqlite_master WHERE type='table'"))
        tables = result.fetchall()
        print(f"数据库中的表: {[table[0] for table in tables]}")
        
        print("\n=== 检查学生数据 ===")
        students = db.query(Student).all()
        for student in students:
            print(f"""
学生ID: {student.id}
学号: {student.student_id}
姓名: {student.name}
邮箱: {student.email}
性别: {student.gender}
是否激活: {student.is_active}
作息习惯: {student.sleeping_habit}
卫生习惯: {student.cleanliness}
------------------------""")
            
    except Exception as e:
        print(f"错误: {str(e)}")
    finally:
        db.close()

if __name__ == "__main__":
    check_database() 